package com.yang.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.yang.entity.Group;
import com.yang.util.DBHelp;
import com.yang.util.MapRow;

public class GroupDao {

	private DBHelp<Group> dh=new DBHelp<Group>();

	public List<Group> findAll(String id) {
		String sql="SELECT * FROM t_group WHERE id in(SELECT groupid FROM t_role WHERE userid=?) order by name";
		MapRow<Group> mr=new Mr();
		return dh.findList(sql, mr,id);
	}
	private class Mr implements MapRow<Group>{
		@Override
		public Group RowMap(ResultSet rs) throws SQLException {
			Group g=new Group();
			g.setId(rs.getString("id"));
			g.setName(rs.getString("name"));
			return g;
		}
		
	}
	public boolean insertGroup(String groupid, String name) {
		String sql="insert into t_group(id,name)values(?,?)";
		return dh.add(sql, groupid,name);
	}
}
